# include <bits/stdc++.h>
# define MAXN 102
using namespace std;

bool m[MAXN][MAXN], vis[MAXN][MAXN];
int n, ans;
int fx[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

inline void dfs(int x, int y) {
    vis[x][y] = 1;
    ans++;
    for(int i = 0; i < 4; i++) {
        int tx = x + fx[i][0], ty = y + fx[i][1];
        if(x > n || x < 1 || y > n || y < 1 || !m[tx][ty] || vis[tx][ty]) continue;
        dfs(tx, ty);
    }
}

char line[102];

int main() {
    freopen("ymxpre.in", "r", stdin);
    freopen("ymxpre.out", "w", stdout);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%s", line + 1);
        for(int j = 1; j <= n; j++) {
            if(line[j] == '0' || line[j] == '2' || line[j] == '5')
                m[i][j] = true;
            else
                m[i][j] = false;
        }
    }
    if (!m[1][1]) {
        printf("no\n0\n");
        return 0;
    }
    dfs(1, 1);
    if(vis[n][n])
        printf("yes\n");
    else
        printf("no\n");
    printf("%d\n", ans);
}